﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz.BusinessObjects;
using Xyz.DataObjects.Interfaces;

namespace Xyz.DataObjects.Entity.Dao
{
    public class EntityMemberPaymentDao : IMemberPaymentDao
    {
        public void CreatePayment(MemberPayment memberPayment)
        {
            var entity = Mapper.Map(memberPayment);

            using (var context = EntityObjectFactory.CreateContext())
            {
                context.MemberPaymentEntities.AddObject(entity);
                context.SaveChanges();
            }
        }

        public MemberPayment GetMemberPaymentByMemberId(int memberId)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var memberPayment = context.MemberPaymentEntities.Single(x => x.MemberId == memberId);

                return Mapper.Map(memberPayment);
            }
        }
    }
}
